package labox.innovation.gameserver.model.actor.instance;

import labox.innovation.gameserver.Announcements;
import labox.innovation.gameserver.model.actor.L2Character;
import labox.innovation.gameserver.templates.chars.NpcTemplate;
import labox.innovation.gameserver.timer.Timer;

/**
 * This class manages all RaidBoss. In a group mob, there are one master called RaidBoss and several slaves called Minions.
 * 
 * @version $Revision: 1.20.4.6 $ $Date: 2005/04/06 16:13:39 $
 */
public class FuzeRaidBossInstance extends FuzeMonsterInstance {

	private static final int RAIDBOSS_MAINTENANCE_INTERVAL = 5000; // 30 sec

	/**
	 * Constructor of L2RaidBossInstance (use L2Character and L2NpcInstance constructor).<BR>
	 * <BR>
	 * 
	 * <B><U> Actions</U> :</B><BR>
	 * <BR>
	 * <li>Call the L2Character constructor to set the _template of the L2RaidBossInstance (copy skills from template to object and link _calculators to NPC_STD_CALCULATOR)</li> <li>Set the name of the L2RaidBossInstance</li> <li>Create a RandomAnimation Task that will be launched after the calculated delay if the server allow it</li><BR>
	 * <BR>
	 * 
	 * @param objectId
	 *            Identifier of the object to initialized
	 * @param L2NpcTemplate
	 *            Template to apply to the NPC
	 */
	public FuzeRaidBossInstance(long objectId, NpcTemplate template) {
		super(objectId, template);
		setIsRaid(true);
	}

	@Override
	public boolean doDie(L2Character killer) {
		if (!super.doDie(killer))
			return false;
		FuzePcInstance player = killer.getActingPlayer();
		if (player != null) {
			Announcements.getInstance().announceToAll("三界流言:修真者 "+player.getName()+" 凝聚体内仙灵之气挥出致命一击，将 "+getPosition().getScene().getName()+" 的BOSS "+getName()+" 斩杀，洪荒修真界中从此又多了一位后起之秀");
		}
		return true;
	}

	/**
	 * Spawn all minions at a regular interval Also if boss is too far from home location at the time of this check, teleport it home
	 * 
	 */
	@Override
	protected void startMaintenanceTask() {
		if (_minionList == null)
			return;
		_minionList.spawnMinions();
		if (_maintenanceTask == null) {
			_maintenanceTask = new Timer(RAIDBOSS_MAINTENANCE_INTERVAL, true, new Runnable() {
				public void run() {
					_minionList.maintainMinions();
				}
			});
		}

		if (!_maintenanceTask.isAlive())
			_maintenanceTask.start();
	}

}
